import { getLayerIdAddLableColor, getLayerIdEchartDataDot, giveEchartDataAddFlawInfo, giveEchartDataAddLableColor } from '@/utils/tool';
import { slitListT } from '../type';

// 接收分条卷的信息，但是md,cd,是返回分开的，需要再次组装后用于前端展示数据
export const handleSlitInfo = (slitList: Array<slitListT>) => {
  // {TD_between + MD_between  + dimensions_between
  const slitInfo: Array<slitListT> = [];
  slitList.forEach((item: slitListT) => {
    const tempObj = {
      ...item
    };
    tempObj['TD_between'] = `${tempObj.x?.toFixed(2) || 0}mm ~ ${(tempObj.x + tempObj.lotWidth)?.toFixed(2) || 0}mm`;
    tempObj['MD_between'] = `${(tempObj.y / 1000)?.toFixed(2) || 0}m ~ ${(tempObj.y / 1000 + tempObj.lotHeight / 1000)?.toFixed(2) || 0}m`;
    tempObj['dimensions_between'] = `${tempObj.size}(${tempObj.sizeLong?.toFixed(2) || 0}*${tempObj.sizeShort?.toFixed(2) || 0})`;
    // delete tempObj.dimensions
    slitInfo.push(tempObj);
  });

  return slitInfo;
};

// 获取矩形坐标信息
export const getRectCoordinateInfo = (rectList: Array<any>) => {
  const infoMap = new Map();
  const coordinateList = [] as any;
  rectList.forEach((item, index) => {
    const { x, y, lotHeight, lotWidth } = item;
    const val = [x, y, lotWidth, lotHeight, index];
    coordinateList[index] = val;
    infoMap.set(index, item);
  });

  const result = {
    coordinateList: coordinateList,
    infoMap: infoMap
  };
  //   console.log('矩形result', result);
  //   console.log('矩形坐标', coordinateList);
  return result;
};

//   合并三个工站的缺陷点数据信息,flag为true代表对应的坐标点必须 x<y
export const merageDotInfo = (dot, commonStore) => {
  const { doff, piantiehou, pol } = dot;
  const doffDot = giveEchartDataAddFlawInfo(doff, commonStore.doffResult.flawTypeSymbolMap, 'doff');
  const doffSeries = giveEchartDataAddLableColor(doffDot);

  const polDot = giveEchartDataAddFlawInfo(pol, commonStore.polResult.flawTypeSymbolMap, 'pol');
  const polSeries = giveEchartDataAddLableColor(polDot);

  const piantiehouDot = giveEchartDataAddFlawInfo(piantiehou, commonStore.pianResult.flawTypeSymbolMap, 'piantiehou');
  const piantiehouSeries = giveEchartDataAddLableColor(piantiehouDot);
  return [...doffSeries, ...piantiehouSeries, ...polSeries];
};

/**
 * 涂层
 * @param dot
 * @param commonStore
 * @returns
 */
export const mergeLayerFlawMapDot = (dot, commonStore) => {
  const { doff, piantiehou, pol } = dot;
  const doffDot = getLayerIdEchartDataDot(doff, commonStore.doffResult.flawTypeSymbolMap);
  const doffSeries = getLayerIdAddLableColor(doffDot);

  const polDot = getLayerIdEchartDataDot(pol, commonStore.polResult.flawTypeSymbolMap);
  const polSeries = getLayerIdAddLableColor(polDot);

  const piantiehouDot = getLayerIdEchartDataDot(piantiehou, commonStore.pianResult.flawTypeSymbolMap);
  const piantiehouSeries = getLayerIdAddLableColor(piantiehouDot);
  return [...doffSeries, ...piantiehouSeries, ...polSeries];
};
